//index.js
//获取应用实例
var common = getApp().common;
var page = 0;
var pageSize = 20;
Page({
    data: {
        scrollTop: {
            scroll_top: 0,
        },
        //首页顶部加载中是否显示
        topjiazai: false,
        showPulldown: false,
        isFixed: false,
        isshow_subsidy: true,
        minprice: '',
        maxprice: '',
        redTriangle: false,
        isShow0: false,
        isShow1: false,
        isShow2: false,
        sort: 0,
        cname: "",
        sortName: "默认",
        currentTab: 0,
        currentTab2: 0,
        autoplay: true,
        interval: 3000,
        from_uid: 0,
        nickname: '',
        memberid: 0,
        datalock: false,
        uri: "list",
        searchkey: "",
        showAnimation: true,
        loadingMore: false,
        duration: 100,
        banner: [
            'http://pic-cdn.35pic.com/58pic/22/24/01/57b85ef98ab58_1024.jpg',
            'http://image.tupian114.com/20161030/0503313512.jpg',
            'http://img.daimg.com/uploads/allimg/180307/1-1P30G42942.jpg'
        ],
        //猜你喜欢的商品
        commodity: [

        ],

        imgmenuPage: [
            [
                1, 2, 3, 4
            ],
            [
                1, 2, 3, 4
            ], [
                1, 2, 3, 4
            ],

        ],

        helpmenu: [
            // {
            //     "img": '../../images/activity3.png',
            //     "name": '省钱看这里',
            //     "url": '../savemoney-help/index'
            // },
            // {
            //     "img": '../../images/activity4.png',
            //     "name": '赚钱看这里',
            //     "url": '../makemoney-help/index'
            // }
        ],

    },
    onPullDownRefresh: function () {
        this.onLoad();
    },
    onLoad: function (options) {
        page = 0;
        this.init(page);
    },
    onTabItemTap(item) {
        //console.log(item);
        this.onLoad();
        wx.pageScrollTo({
            scrollTop: 0,
        })
    },
    onShareAppMessage: function (res) {
        var memberinfo = wx.getStorageSync("memberinfo");
        if (res.from === 'button') {
            // 来自页面内转发按钮
        }

        return {
            title: this.data.globalset.title,
            path: '/haojk/pages/index/index?from_uid=' + memberinfo.memberid + '&from_nickname=' + memberinfo.nickname + '&type=' + memberinfo.type + '&homeskinid=' + memberinfo.homeskinid,
            success: function (res) {
                // 转发成功
            },
            fail: function (res) {
                // 转发失败
            }
        }

    },

    onReachBottom: function () {
        var is_loading = this.data.loadingMore;
        if (!is_loading) this.init();
    },
    //页面初始化
    init: function () {
        var that = this;
        that.setData({ loadingMore: true });
        var fn = function (data) {
            //请求成功的回调函数
            data.goodsList = common.trim_array(data.goodsList);
            if (page == 0) {
                that.setData({ commodity: data.goodsList })
            } else {
                var goodsList = that.data.commodity.concat(data.goodsList);
                that.setData({ commodity: goodsList })
            }
            page++;
        }
        var option = {
            apiHost: 'https://jd.open.apith.cn/union/',
            api: 'queryCouponGoods',
            data: { pageIndex: page * pageSize, pageSize: pageSize,priceTo:10 },
            successCode: 1,
            fn: fn,
            completeFn: function () {      //请求完成的回调函数
                that.setData({ loadingMore: false });
            }
        };
        common.request(option);
    },
    skiptodetail: function (e) {
        var skuid = e.currentTarget.dataset.skuid;
        var couponUrl = e.currentTarget.dataset.couponurl;

        wx.navigateTo({
            url: '../detail/index?skuid=' + skuid + '&couponUrl=' + common.URLEncode(couponUrl),
        })


    }
})
